package main

import (
	"bytes"
	"encoding/binary"
	"fmt"
	//"mono-replicator/mono/utils"
	//"regexp"
	//"strings"
)

type BinLogOp struct {
	Op     string
	Time   string
	Schema string
	Table  string
	Column []string
	BeVal  []string
	AfVal  []string
	Ids    []string
	Sql    string
}

func main() {
	//ss := "enum('x-small','small','medium','large','x-large')"
	//ss := "decimal(20,7)"
	//kv := strings.Split(ss[strings.Index(ss, "(")+1:strings.Index(ss, ")")], ",")
	//fmt.Println(kv)
	//var n uint64 = 7 //9223372036854775808
	//regSMath := regexp.MustCompile("[\\d]+")
	//
	//bytesBuffer := bytes.NewBuffer([]byte{})
	//binary.Write(bytesBuffer, binary.BigEndian, &n)
	//utils.BytesToBinaryString(bytesBuffer.Bytes())
	//
	//s := utils.BytesToBinaryString(bytesBuffer.Bytes())
	//var tmp string
	//for i := 0; i < len(regSMath.FindAllString(s, -1)); i++ {
	//	tmp += regSMath.FindAllString(s, -1)[i]
	//}
	//
	//fmt.Println(reverse(tmp))

	//binlog := new(BinLogOp)
	//binlog.Op = "INSERT"
	//binlog.Schema = "dbmanager"
	//binlog.Sql = "alter"
	//binlog.Column = append(binlog.Column, "col")
	//binlog.BeVal = append(binlog.BeVal, "a,b,c")
	//iValues, _ := json.Marshal(binlog)
	fmt.Println((1 + 7) / 8)
}
func reverse(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}
func Byte2Int(data []byte) int32 {
	binBuf := bytes.NewBuffer(data)
	var x int32
	binary.Read(binBuf, binary.LittleEndian, &x)
	return x
}

func DeciNeedBytes(len int) int {
	var l int
	for {
		if len <= 0 {
			break
		}

		// 7-9
		if len >= 9 {
			l += 4
			len -= 9
		}
		if len == 8 {
			l += 4
			len -= 9
		}
		if len == 7 {
			l += 4
			len -= 7
		}
		// 5-6
		if len == 6 {
			l += 3
			len -= 6
		}
		if len == 5 {
			l += 3
			len -= 5
		}
		// 3-4
		if len == 4 {
			l += 2
			len -= 4
		}
		if len == 3 {
			l += 2
			len -= 3
		}
		// 1-2
		if len == 2 {
			l += 1
			len -= 2
		}
		if len == 1 {
			l += 1
			len -= 1
		}
	}
	return l
}
